package com.wnhz.work.jy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wnhz.work.jy.R;
import com.wnhz.work.jy.bean.MyAddGridViewBean;

import java.util.List;

/**
 * Created by Administrator on 2016/10/8 0008.
 */
public class MyAddGridViewAdapter extends BaseAdapter {
    private LayoutInflater mInflater;
    private Context context;
    private List<MyAddGridViewBean> Mylist;
    private int screenWidth;

    private boolean isMember;

    public boolean isMember() {
        return isMember;
    }

    public void setMember(boolean member) {
        isMember = member;
    }

    public MyAddGridViewAdapter(Context context, List<MyAddGridViewBean> Mylist, int screenWidth) {
        mInflater = LayoutInflater.from(context);
        this.context = context;
        this.Mylist = Mylist;
        this.screenWidth = screenWidth;
    }

    @Override
    public int getCount() {
        if (isMember){
            return Mylist.size();
        }
        return Mylist.size()-2;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        AddGridViewViewHolder viewHolder = new AddGridViewViewHolder();
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.my_add_gridview_item, null);
            viewHolder.mImg = (ImageView) convertView.findViewById(R.id.iv_pic);
            viewHolder.title = (TextView) convertView.findViewById(R.id.tv_title);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (AddGridViewViewHolder) convertView.getTag();
        }

        /*int width = screenWidth / 4;

        ViewGroup.LayoutParams params = viewHolder.mImg.getLayoutParams();

        params.width = width;
        params.height = width;

        viewHolder.mImg.setLayoutParams(params);*/

//        ImageLoader.getInstance().displayImage(Mylist.get(position).getImage(),viewHolder.mImg);
        if (!"0".equals(Mylist.get(position).getImage()) && Mylist.get(position).getImage() != null) {
            viewHolder.mImg.setImageResource(Integer.parseInt(Mylist.get(position).getImage()));
        }else {
            viewHolder.mImg.setVisibility(View.INVISIBLE);
        }

        if (!"".equals(Mylist.get(position).getTitle()) && Mylist.get(position).getTitle() != null){
            viewHolder.title.setText(Mylist.get(position).getTitle());
        }else {
            viewHolder.title.setVisibility(View.INVISIBLE);
        }

        return convertView;
    }

    class AddGridViewViewHolder {
        ImageView mImg;
        TextView title;
    }
}
